package com.superman.supermarket.client.activity;

import java.util.HashMap;
import java.util.Map;

import com.google.gwt.event.shared.EventBus;
import com.google.inject.Inject;
import com.superman.mvpframe.client.ajax.PostManAsyncCallBack;
import com.superman.mvpframe.client.event.ToastEvent;
import com.superman.mvpframe.client.mvp.IPageView;
import com.superman.mvpframe.client.mvp.IPageViewPresenter;
import com.superman.mvpframe.client.utils.XJsonUtil;
import com.superman.supermarket.client.mvp.ShopAbstractActivity;
import com.superman.supermarket.client.view.addredit.AddrEditView;
import com.superman.supermarket.client.view.addredit.AddrEditView.AddrEditViewPresenter;

/**
 * 地址新建
 * 
 * @author superman
 * @version 2018年8月2日下午5:02:24
 */
public class AddrNewActivity extends ShopAbstractActivity implements AddrEditViewPresenter {

	@Inject
	AddrEditView addrEditView;

	@Override
	public IPageView getView() {
		return addrEditView;
	}

	@Override
	public IPageViewPresenter getViewPresenter() {
		return this;
	}

	@Override
	public void onActivity(EventBus eventBus) {
		addrEditView.setHeaderText("新建收货地址");
	}

	@Override
	public void popToRefresh() {
		// TODO Auto-generated method stub

	}

	@Override
	public void popToRefresh(Object contextData) {
		// TODO Auto-generated method stub

	}

	@Override
	public void pushToRefresh() {
		// TODO Auto-generated method stub

	}

	@Override
	public void save(String receivername, String telno, String areacode, String area, String address) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("RECEIVER", receivername);
		map.put("PHONE_NO", telno);
		map.put("AREA_CODE", areacode);
		map.put("AREA", area);
		map.put("DETAIL_ADDR", address);
		postman.post("address/add", map, new PostManAsyncCallBack() {

			@Override
			public void onBusinessError(String statusCode) {

			}

			@Override
			public void onBusinessOK(String response) {
				eventBus.fireEvent(new ToastEvent("地址添加成功"));

				placeController.back(XJsonUtil.getBody(response));
			}
		});
	}

}
